<?php
require_once 'Shared/Models/Comment.php';
require_once 'Shared/Models/Scontent.php';
require_once 'Shared/Models/ScontentCategory.php';
class commentSticker extends Vi_Sticker
{
	public function run()
	{
		$params = $this->getParams(); // scontent_id 
		$objComment = new Models_Comment();
		$errors = array();
		
		if(null != @$_POST['data_comment']) {
			$objScontent = new Models_Scontent();
//			$select = $objScontent->select()
//								->where("scontent_id = ?",$params[scontentId]);
//			$objScontent = current($objScontent->fetchAll($select)->toArray());
			$objScontent = $objScontent->getContentById($params[scontentId]);
			$_POST["scontent_id"] = $params[scontentId];
//			$_POST["scontent_category_id"] = $objScontent[scontent_category_id];
			$_POST["portal_id"] = $objScontent[portal_id];
			if ($_SESSION['captcha'] != strtoupper($_POST['data_comment'][captcha])) {
                /**
                 * Incorrect captcha
                 */
                if (! is_array($errors)) {
                    $errors = array();
                }
                $errors[] = 'Captcha is incorrect';
            } else {
				$comment = array(
				               'portal_id'   => $_POST["portal_id"],
							   'scontent_id' => $_POST["scontent_id"],
	//						   'scontent_category_id' => $_POST["scontent_category_id"],
							   'name'        => $_POST['data_comment'][name],
				               'email'       => $_POST['data_comment'][email],
							   'comment'     => $_POST['data_comment'][comment],
							   'enabled'     => 1
				               );
				$objComment->insert($comment);
				unset($_POST);
            }
		}
		$allComments = $objComment->getAll()->toArray();
		$this->view->allComments = $allComments;
		$this->view->errors = $errors;
	}
}